package com.dy.nygl.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.dy.nygl.pojo.DayYear;
import com.dy.nygl.pojo.Energy;
import com.dy.nygl.pojo.EnergyYear;
import com.dy.nygl.pojo.FromTo;
import com.dy.nygl.service.DayYearService;
import com.dy.nygl.service.EnergyService;
import com.dy.nygl.service.EnergyYearService;
import com.dy.nygl.service.FromToService;

@Controller
@RequestMapping("dayYear")
public class DayYearController {

	@Resource(name = "dayyearService")
	private DayYearService dayyearService;

	private List<DayYear> dayYearList;

	private List<Energy> energyList;

	@Resource(name = "energyService")
	private EnergyService energyService;

	private List<EnergyYear> energyYearList;

	@Resource(name = "energyYearService")
	private EnergyYearService energyYearService;

	@Resource(name = "fromToService")
	private FromToService fromToService;

	private String beginDate;

	private String endDate;

	private String select;

	private int beginId;

	private int EndId;

	public int getBeginId() {
		return beginId;
	}

	public void setBeginId(int beginId) {
		this.beginId = beginId;
	}

	public int getEndId() {
		return EndId;
	}

	public void setEndId(int endId) {
		EndId = endId;
	}

	public String getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getSelect() {
		return select;
	}

	public void setSelect(String select) {
		this.select = select;
	}

	public List<DayYear> getDayYearList() {
		return dayYearList;
	}

	public void setDayYearList(List<DayYear> dayYearList) {
		this.dayYearList = dayYearList;
	}

	@RequestMapping("/setPeriods.action")
	public void setPeriods(HttpServletResponse response, HttpSession session) throws ServletException, IOException {
		beginId = getBeginId();
		EndId = getEndId();
		System.err.println("------>BeiginId:" + beginId + "------->EndId：" + EndId);
		dayYearList = null;
		dayYearList = dayyearService.selectPeriods(beginId, EndId);
		setDayYearList(dayYearList);
		updatePicShow(dayYearList);
		updateFromTo();
		PrintWriter out = response.getWriter();
		out.print(1);

	}

	@RequestMapping("/calMonth.action")
	public void setMonthOfYear(HttpServletResponse response)throws IOException {
		List<DayYear> listJan = dayyearService.selectPeriods(1, 31);
		List<DayYear> listFeb = dayyearService.selectPeriods(32, 60);
		List<DayYear> listMar = dayyearService.selectPeriods(61, 90);
		List<DayYear> listApr = dayyearService.selectPeriods(91, 120);
		List<DayYear> listMay = dayyearService.selectPeriods(121, 151);
		List<DayYear> listJune = dayyearService.selectPeriods(152, 181);
		List<DayYear> listJuly = dayyearService.selectPeriods(182, 212);
		List<DayYear> listAug = dayyearService.selectPeriods(213, 243);
		List<DayYear> listSep = dayyearService.selectPeriods(244, 273);
		List<DayYear> listOct = dayyearService.selectPeriods(274, 304);
		List<DayYear> listNov = dayyearService.selectPeriods(305, 334);
		List<DayYear> listDec = dayyearService.selectPeriods(335, 365);

		updateMonthOfYear(listJan, 1);
		updateMonthOfYear(listFeb, 2);
		updateMonthOfYear(listMar, 3);
		updateMonthOfYear(listApr, 4);
		updateMonthOfYear(listMay, 5);
		updateMonthOfYear(listJune, 6);
		updateMonthOfYear(listJuly, 7);
		updateMonthOfYear(listAug, 8);
		updateMonthOfYear(listSep, 9);
		updateMonthOfYear(listOct, 10);
		updateMonthOfYear(listNov, 11);
		updateMonthOfYear(listDec, 12);
		
		PrintWriter out=response.getWriter();
		out.print(2);
		
	}

	public void updateMonthOfYear(List<DayYear> list, int month) {
		int sumElec = 0;
		int sumWater = 0;
		int sumNatur = 0;
		int sumGas = 0;
		int sumDerv = 0;
		int sumCoal = 0;

		for (DayYear daylist : list) {
			sumElec = sumElec + daylist.getElec();
			sumWater = sumWater + daylist.getWater();
			sumNatur = sumNatur + daylist.getNatur();
			sumGas = sumGas + daylist.getGasonline();
			sumDerv = sumDerv + daylist.getDerv();
			sumCoal = sumCoal + daylist.getCoal();
		}

		if (month == 1) {
			updateJan(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 2) {
			updateFeb(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 3) {
			updateMar(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 4) {
			updateApr(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 5) {
			updateMay(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 6) {
			updateJun(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 7) {
			updateJuly(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 8) {
			updateAug(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 9) {
			updateSep(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 10) {
			updateOct(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 11) {
			updateNov(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		} else if (month == 12) {
			updateDec(sumElec, sumWater, sumNatur, sumGas, sumDerv, sumCoal);
		}

	}

	public void updateJan(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setJan(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setJan(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setJan(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setJan(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setJan(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setJan(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	
	public void updateFeb(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setFeb(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setFeb(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setFeb(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setFeb(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setFeb(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setFeb(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateMar(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setMar(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setMar(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setMar(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setMar(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setMar(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setMar(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateApr(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setApr(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setApr(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setApr(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setApr(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setApr(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setApr(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateMay(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setMay(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setMay(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setMay(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setMay(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setMay(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setMay(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateJun(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setJun(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setJun(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setJun(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setJun(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setJun(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setJun(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateJuly(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setJuly(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setJuly(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setJuly(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setJuly(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setJuly(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setJuly(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateAug(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setAug(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setAug(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setAug(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setAug(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setAug(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setAug(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateSep(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setSep(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setSep(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setSep(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setSep(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setSep(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setSep(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateOct(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setOct(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setOct(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setOct(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setOct(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setOct(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setOct(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateNov(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setNov(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setNov(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setNov(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setNov(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setNov(String.valueOf(sumDerv));
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setNov(String.valueOf(sumCoal));
		energyYearService.update(energyYear6);
	}
	public void updateDec(int sumElec, int sumWater, int sumNatur, int sumGas, int sumDerv, int sumCoal) {
		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setDec1(String.valueOf(sumElec));
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setDec1(String.valueOf(sumWater));
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setDec1(String.valueOf(sumNatur));
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setDec1(String.valueOf(sumGas));
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setDec1(sumDerv + "");
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setDec1(sumCoal + "");
		energyYearService.update(energyYear6);
	}


	public void updateFromTo() {
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
		Date date = new Date();
		FromTo fromTo = new FromTo();
		String from = getBeginDate();
		String to = getEndDate();
		fromTo.setId(1);
		fromTo.setFromgo(from);
		fromTo.setTogo(to);
		fromTo.setCreatetime(dateFormater.format(date));
		fromToService.update(fromTo);
	}

	public void updatePicShow(List<DayYear> list) {
		int sumElec = 0;
		int sumWater = 0;
		int sumNatur = 0;
		int sumGas = 0;
		int sumDerv = 0;
		int sumCoal = 0;

		for (DayYear daylist : list) {
			sumElec = sumElec + daylist.getElec();
			sumWater = sumWater + daylist.getWater();
			sumNatur = sumNatur + daylist.getNatur();
			sumGas = sumGas + daylist.getGasonline();
			sumDerv = sumDerv + daylist.getDerv();
			sumCoal = sumCoal + daylist.getCoal();
		}
		System.out.println(sumElec);
		System.out.println(sumWater);
		System.out.println(sumNatur);
		System.out.println(sumGas);
		System.out.println(sumDerv);
		System.out.println(sumCoal);

		Random ra = new Random();
		Energy energy1 = new Energy();
		energy1.setId(1);
		energy1.setActual(sumWater + "");
		energy1.setPredict(sumWater - ra.nextInt(100) + "");
		energyService.update(energy1);

		Energy energy2 = new Energy();
		energy2.setId(2);
		energy2.setActual(sumElec + "");
		energy2.setPredict(sumElec - ra.nextInt(100) + "");
		energyService.update(energy2);

		Energy energy3 = new Energy();
		energy3.setId(3);
		energy3.setActual(sumNatur + "");
		energy3.setPredict(sumNatur - ra.nextInt(100) + "");
		energyService.update(energy3);

		Energy energy4 = new Energy();
		energy4.setId(4);
		energy4.setActual(sumGas + "");
		energy4.setPredict(sumGas - ra.nextInt(100) + "");
		energyService.update(energy4);

		Energy energy5 = new Energy();
		energy5.setId(5);
		energy5.setActual(sumDerv + "");
		energy5.setPredict(sumDerv - ra.nextInt(100) + "");
		energyService.update(energy5);

		Energy energy6 = new Energy();
		energy6.setId(6);
		energy6.setActual(sumCoal + "");
		energy6.setPredict(sumCoal - ra.nextInt(100) + "");
		energyService.update(energy6);
	}

	@RequestMapping("/setBeginDate.action")
	public void setBeginDate(@RequestParam("beginDate") String beginDate, HttpServletResponse response,
			HttpSession session) throws ServletException, IOException {
		setBeginDate(beginDate);
		beginId = 0;
		beginId = dayyearService.selectByDate(beginDate).getId();
		setBeginId(beginId);
	}

	@RequestMapping("/setEndDate.action")
	public void setEndDate(@RequestParam("endDate") String endDate, HttpServletResponse response, HttpSession session)
			throws ServletException, IOException {
		setEndDate(endDate);
		EndId = 0;
		EndId = dayyearService.selectByDate(endDate).getId();
		setEndId(EndId);
	}

	@RequestMapping("/setSelect.action")
	public void setSelect(@RequestParam("select") String select, HttpServletResponse response, HttpSession session)
			throws ServletException, IOException {
		setSelect(select);
	}

	@RequestMapping("/getList.action")
	public ModelAndView getList() {
		dayYearList = getDayYearList();
		ModelAndView model = new ModelAndView();
		model.addObject("dayYearList", dayYearList);
		model.setViewName("energy_usage");
		return model;

	}

	@RequestMapping("/getList1.action")
	public ModelAndView getList1() {
		dayYearList = getDayYearList();
		ModelAndView model = new ModelAndView();
		model.addObject("dayYearList", dayYearList);
		model.setViewName("consum_plan_manage");
		return model;

	}

	@RequestMapping("/getLike.action")
	public void getLikeList() {
		dayYearList = null;
		dayYearList = dayyearService.selectLike("2016-1-%");
		System.out.println(dayYearList);
		int sumElec = 0;
		int sumWater = 0;
		int sumNatur = 0;
		int sumGas = 0;
		int sumDerv = 0;
		int sumCoal = 0;

		for (DayYear daylist : dayYearList) {
			sumElec = sumElec + daylist.getElec();
			sumWater = sumWater + daylist.getWater();
			sumNatur = sumNatur + daylist.getNatur();
			sumGas = sumGas + daylist.getGasonline();
			sumDerv = sumDerv + daylist.getDerv();
			sumCoal = sumCoal + daylist.getCoal();
		}
		System.out.println(sumElec);
		System.out.println(sumWater);
		System.out.println(sumNatur);
		System.out.println(sumGas);
		System.out.println(sumDerv);
		System.out.println(sumCoal);

		EnergyYear energyYear1 = new EnergyYear();
		energyYear1.setId(1);
		energyYear1.setJan(sumElec + "");
		energyYearService.update(energyYear1);

		EnergyYear energyYear2 = new EnergyYear();
		energyYear2.setId(2);
		energyYear2.setJan(sumWater + "");
		energyYearService.update(energyYear2);

		EnergyYear energyYear3 = new EnergyYear();
		energyYear3.setId(3);
		energyYear3.setJan(sumNatur + "");
		energyYearService.update(energyYear3);

		EnergyYear energyYear4 = new EnergyYear();
		energyYear4.setId(4);
		energyYear4.setJan(sumGas + "");
		energyYearService.update(energyYear4);

		EnergyYear energyYear5 = new EnergyYear();
		energyYear5.setId(5);
		energyYear5.setJan(sumDerv + "");
		energyYearService.update(energyYear5);

		EnergyYear energyYear6 = new EnergyYear();
		energyYear6.setId(6);
		energyYear6.setJan(sumCoal + "");
		energyYearService.update(energyYear6);

	}

	@RequestMapping("/insert.action")
	public void insert() {
		Random ra = new Random();
		DayYear dayYear = new DayYear();
		for (int i = 1; i < 350; i++) {

			dayYear.setName(i + "");
			dayYear.setElec(ra.nextInt(50) + 1);
			dayYear.setWater(ra.nextInt(50) + 1);
			dayYear.setNatur(ra.nextInt(50) + 1);
			dayYear.setGasonline(ra.nextInt(50) + 1);
			dayYear.setDerv(ra.nextInt(50) + 1);
			dayYear.setCoal(ra.nextInt(50) + 1);
			dayYear.setDate("2016-1-" + i);
			dayyearService.insert(dayYear);
		}
	}

	@RequestMapping("/update.action")
	public void update() {
		Random ra = new Random();
		DayYear dayYear = new DayYear();
		for (int i = 10; i < 32; i++) {
			dayYear.setId(i + 334);
			dayYear.setName(i + "");
			dayYear.setElec(ra.nextInt(50) + 1);
			dayYear.setWater(ra.nextInt(50) + 1);
			dayYear.setNatur(ra.nextInt(50) + 1);
			dayYear.setGasonline(ra.nextInt(50) + 1);
			dayYear.setDerv(ra.nextInt(50) + 1);
			dayYear.setCoal(ra.nextInt(50) + 1);
			dayYear.setDate("2016-12-" + i);
			dayyearService.update(dayYear);
		}
	}
}
